package threadStudy;

import java.util.Scanner;

public class ThreadAStopThreadB {
    public static void main(String[] args) {
        A a = new A();
        B b = new B(a);
        a.start();
        b.start();
    }
}
class A extends Thread {
    boolean flag = true;
    @Override
    public void run() {
        while (flag) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("A线程正在跑");
        }
        System.out.println("A线程寄了");
    }
    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
class B extends Thread {
    A a;
    public B (A a) {
        this.a = a;
    }
    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        a.flag = false;
    }
}